/**
 * 审核文章页需要的js文件
 */
layui.use('layer', function () {
    var layer = layui.layer;

    /******************文章通过审核*****************************/
    $("#cross").click(function () {
        var essayId = $(this).attr("essayId");
        $.ajax({
            type: 'POST',
            url: '/manager/passEssay.do',
            data: {
                essayId: essayId
            },
            success: function (value) {
                if (value == "success") {
                    layer.msg("通过审核，即将跳转", {
                        icon: 1,
                        time: 500
                    }, function () {
                        window.location.href = "/manager/messageredirect.do"
                    });
                } else if (value == "false") {
                    layer.msg("服务器好像出错了，请稍后重试", {
                        icon: 2,
                        time: 500
                    }, function () {
                        window.location.href = "/manager/messageredirect.do"
                    });
                } else if (value == "alreadyAuditing") {
                    layer.msg("已经审核过该文章了", {
                        icon: 1,
                        time: 500
                    });
                }
            }
        });
    });

    /****************文章不通过审核（返回删除消息以及原因）************************/
    $("#delete").click(function () {
        var essayId = $(this).attr("essayId");
        var messageId = $(this).attr("messageId");
        layer.prompt({
            formType: 2,
            title: '请输入删除原因以及提醒,同时将删除此条消息',
            area: ['500px', '200px'] //自定义文本域宽高
        }, function (value, index, elem) {
            if (value != null && value != '') {
                $.ajax({
                    type: 'POST',
                    url: '/manager/DeleteEssay.do',
                    data: {
                        essayId: essayId,
                        content: value,
                        messageId: messageId
                    },
                    success: function (data) {
                        if (data == "success") {
                            layer.msg("操作成功，即将跳转", {
                                icon: 1,
                                time: 500
                            }, function () {
                                window.location.href = "/manager/messageredirect.do"
                            });
                        } else if (data == "false") {
                            layer.msg("服务器好像出错了，请稍后重试", {
                                icon: 2,
                                time: 500
                            }, function () {
                                window.location.href = "/manager/messageredirect.do"
                            });
                        }
                    }
                });
            } else {
                layer.msg("请输入删除原因！！", {
                    icon: 2,
                    time: 500
                });
            }

            layer.close(index);
        });
    })

    /***********************下载文件***********************************/
    $("[name='download']").click(function () {
        var filePath = $(this).attr("filePath");
        window.location.href = "/fileControll/ManagerDownloadFile.do?filePath=" + filePath
    });


});